package quick.portal.service;

import java.util.Map;

import quick.common.AppContext;
import quick.communication.AsyncHttpResponseHandler;
import quick.communication.HttpClient;
import quick.communication.RequestParams;
import quick.portal.R;

public class BaseService {
	
	protected static String portal_url = AppContext.getInstance().getString(R.string.portal_url);
	
	protected static String api_url = AppContext.getInstance().getString(R.string.api_url);
	
	
	protected RequestParams getParams()
	{
		String token = AppContext.getInstance().getToken();
		
		RequestParams params = new RequestParams();		
		params.AddParam(AppContext.Login_Token_Key, token);

		return params;
	}
	
	public static String getPortalUrl()
	{
		return portal_url;
	}
	
	public static String getApiUrl()
	{
		return api_url;
	}
	
	public void List(int pageIndex,int pageSize,String action,AsyncHttpResponseHandler handler)
	{
		RequestParams params = this.getParams()
				.AddParam("PageIndex", String.valueOf(pageIndex))
				.AddParam("PageSize", String.valueOf(pageSize));
		
		HttpClient.get(api_url+action, params, handler);
	}
	
	public void GetObject(Map<String,String> params,String action,AsyncHttpResponseHandler handler)
	{
		RequestParams queryParams = this.getParams();
		
		for(String key:params.keySet())
		{
			queryParams.AddParam(key, params.get(key));
		}
		
		HttpClient.get(api_url+action, queryParams, handler);
	}
	
	public void GetObject(String action,AsyncHttpResponseHandler handler)
	{
		RequestParams queryParams = this.getParams();
		
		HttpClient.get(api_url+action, queryParams, handler);
	}
}
